<?php

	require_once(realpath(dirname(__FILE__)) . "/Cnx.class.php");

	// Classe Request

	// table --> table à requêter

	class Requete extends Cnx{

		var $table = "";

		function __construct(){
			parent::__construct();
		}

		function charger(){
			$varid = $this->bddvars[0];
			return $this->getVars("select * from `$this->table` where `$varid`=\"" . $this->$varid . "\"");

		}

		function add(){

			$query = "insert into `$this->table` (" . $this->getListVarsSql() . ") values(" . $this->getListValsSql() . ")";
			$resul = $this->query($query);
			CacheBase::getCache()->reset_cache();
			return mysql_insert_id();

		}


		function delete(){
			$varid = $this->bddvars[0];
			$query = "delete from `$this->table` where `$varid`=\"" . $this->$varid . "\"";
			if($this->$varid != ""){
				$resul = $this->query($query);
				CacheBase::getCache()->reset_cache();
			}
		}

		function maj(){
			$listv = "";

			$varid = $this->bddvars[0];

			foreach($this->bddvars as $var){
				$val = $this->$var;

				if(get_magic_quotes_gpc())
					$val = stripslashes($val);

				$val = mysql_real_escape_string($val, $this->link);

				$listv.= '`'.$var . "`=\"" . $val . "\",";
			}

			$query = "update `$this->table` set " . rtrim($listv, ',') . " where `$varid`=\"" . $this->$varid . "\"";

			if($this->$varid != "") {
				$resul = $this->query($query);

				CacheBase::getCache()->reset_cache();
			}

			return $query;
		}

		function purge(){
			$query = "truncate table `$this->table` ";
			$resul = $this->query($query);
		}
	}

?>